import 'package:safemap/safemap.dart';

import 'vehicle_data_base.dart';

// 实时状态类
class VehicleRealtimeStatus extends VehicleDataBase {
  bool isHmicRunModeDisabled = false; // 失能状态
  bool isHmicRunModeWorking = false; // 工作状态
  bool isHmicRunModeSleeping = false; // 休眠状态
  bool isHmicRunModeLocked = false; // 锁车状态
  bool isMcRunModeNormalDisabled = false; // 正常失能状态
  bool isMcRunModeNormalBalanced = false; // 正常平衡状态
  bool isMcRunModeProtectTilted = false; // 保护翘板状态
  bool isMcRunModeProtectDisabled = false; // 保护失能状态
  bool isMcRunModeMotorLocked = false; // 电机锁死状态
  bool isMcRunModeNoLoadProtected = false; // 空载保护状态
  bool isMcRunModeLoadDetection = false; // 负载检测状态
  bool isMcRunModeAssistBalanced = false; // 辅助平衡状态
  bool isMotorWorking = false; // 电机在工作状态
  bool isCharging = false; // 充电状态
  bool isBackupBatteryConnected = false; // 备用电池已接入
  int chargePortDetect = 0; // 充电口检测状态
  bool isChargePortOn = false; // 充电口开启状态
  int dcPortDetect = 0; // 直流口检测状态
  bool isDcOutputEnabled = false; // 直流输出口开启状态
  int isLampOn = 0; // 照明灯开启状态
  int isDecorativeLightOn = 0; // 装饰灯开启状态
  bool isLifted = false; // 提手触发状态
  int tailLightState = 0; // 尾灯状态
  bool isFanWorking = false; // 风扇开启状态
  bool isBraking = false; // 制动状态
  bool isSlowingDown = false; // 减速状态
  bool isDfuState = false; // 有设备在固件升级中

  VehicleRealtimeStatus.fromMap(Map<String, dynamic>? data)
      : super.fromMap(data) {
    SafeMap safeMap = SafeMap(data);
    isHmicRunModeDisabled = safeMap['hmic_run_mode'].toInt == 0;
    isHmicRunModeWorking = safeMap['hmic_run_mode'].toInt == 1;
    isHmicRunModeSleeping = safeMap['hmic_run_mode'].toInt == 2;
    isHmicRunModeLocked = safeMap['hmic_run_mode'].toInt == 3;
    isMcRunModeNormalDisabled = safeMap['mc_run_mode'].toInt == 0;
    isMcRunModeNormalBalanced = safeMap['mc_run_mode'].toInt == 1;
    isMcRunModeProtectTilted = safeMap['mc_run_mode'].toInt == 2;
    isMcRunModeProtectDisabled = safeMap['mc_run_mode'].toInt == 3;
    isMcRunModeMotorLocked = safeMap['mc_run_mode'].toInt == 4;
    isMcRunModeNoLoadProtected = safeMap['mc_run_mode'].toInt == 5;
    isMcRunModeLoadDetection = safeMap['mc_run_mode'].toInt == 6;
    isMcRunModeAssistBalanced = safeMap['mc_run_mode'].toInt == 7;
    isMotorWorking = safeMap['motor_work'].toInt == 1;
    isCharging = safeMap['charge_state'].toInt == 1;
    isBackupBatteryConnected = safeMap['backup_battery'].toInt == 1;
    chargePortDetect = safeMap['charge_port_detect'].toInt ?? 0;
    isChargePortOn = safeMap['charge_port_on'].toInt == 1;
    dcPortDetect = safeMap['dc_port_detect'].toInt ?? 0;
    isDcOutputEnabled = safeMap['dc_output_enable'].toInt == 1;
    isLampOn = safeMap['lamp_state'].toInt ?? 0;
    isDecorativeLightOn = safeMap['decorative_light'].toInt ?? 0;
    isLifted = safeMap['lifted'].toInt == 1;
    tailLightState = safeMap['tail_light'].toInt ?? 0;
    isFanWorking = safeMap['fan_work'].toInt == 1;
    isBraking = safeMap['brake'].toInt == 1;
    isSlowingDown = safeMap['slow_down'].toInt == 1;
    isDfuState = safeMap['dfu_state'].toInt == 1;
  }
}


/*
      uint32_t hmic_run_mode      : 3; //0 失能状态         1 工作状态
                                     //2 休眠状态         3 锁车状态
    uint32_t mc_run_mode        : 3; //0 正常失能状态     1 正常平衡状态
                                     //2 保护翘板状态     3 保护失能状态
                                     //4 电机锁死状态     5 空载保护状态
                                     //6 负载检测状态     7 辅助平衡状态
    uint32_t motor_work         : 1; //0 电机在非工作状态 1 电机在工作状态
    uint32_t charge_state       : 1; //0 非充电状态       1 充电状态
    uint32_t backup_battery     : 1; //0 备用电池未接入   1 备用电池已接入
    uint32_t charge_port_detect : 3; //0 无任何设备接入     1 充电器插入   2 备用电池输出口插入  3 另一台车的直流输出口接入  4 不能识别的设备

    uint32_t charge_port_on     : 1; //0 充电口关闭状态     1 充电口开启状态
    uint32_t dc_port_detect     : 3; //0 无任何设备接入     1 逆变器插入   2 备用电池充电口插入  3 另一台车的充电口接入  4 不能识别的设备
    uint32_t dc_output_enable   : 1; //0 直流输出口关闭     1 直流输出口开启
    uint32_t lamp_state         : 1; //0 照明灯关闭状态   1 照明灯开启状态
    uint32_t decorative_light   : 1; //0 装饰灯关闭状态   1 装饰灯开启状态
    uint32_t lifted             : 1; //0 提手未触发状态   1 提手触发状态
    uint32_t tail_light         : 3; //0 尾灯关闭状态
                                     //1 尾灯低亮状态
                                     //2 尾灯高亮状态（刹车指示）
                                     //3 尾灯闪烁状态
                                     //4~7 保留
    uint32_t fan_work           : 1; //0 风扇关闭状态     1 风扇开启状态
    uint32_t brake              : 1; //0 非制动状态       1 制动状态
    uint32_t slow_down          : 1; //0 非减速状态       1 减速状态（和刹车指示灯同步，但不一定是制动状态）
    uint32_t dfu_state          : 1; //0 无固件升级       1 有设备在固件升级中
    uint32_t reserve            : 5; //保留
*/